<template>
    <div class="top-header">
        <section>
            <h1>陈子龙-13790091315</h1>
            <el-icon>
                <Grid />
            </el-icon>
        </section>
        <button @click="handlescreent">{{ icon? "全屏": "缩放" }}</button>
        <el-dropdown @command="handleClick">
            <span class="el-dropdown-link">
                {{ $t("msg.name") }}
                <el-icon class="el-icon--right">
                    <arrow-down />
                </el-icon>
            </span>
            <template #dropdown>
                <el-dropdown-menu>
                    <el-dropdown-item command="home">首页</el-dropdown-item>
                    <el-dropdown-item command="logout">退出</el-dropdown-item>
                    <el-dropdown-item command="zh" :disabled="currentLanguage == 'zh'">中文</el-dropdown-item>
                    <el-dropdown-item command="en" :disabled="currentLanguage == 'en'">英文</el-dropdown-item>
                </el-dropdown-menu>
            </template>
        </el-dropdown>
    </div>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import { ArrowDown, Grid } from '@element-plus/icons-vue';
import { useRouter } from 'vue-router';
import { useUserStore } from '../store/user/index';
import { computed, ref, onMounted } from "vue";
import screenfull from 'screenfull';
const router = useRouter();
const store = useUserStore();
const i18n = useI18n()
const icon = ref(true)
const handleClick = (command: string) => {
    if (command === 'home') {
        // 回到首页
        router.push('/index');
    } else if (command === 'logout') {
        // 回到登录
        router.push('/login');
        // 清除token
        localStorage.removeItem('token');
        // 清除动态路由
        store.activeMenus.forEach(item => {
            router.removeRoute(item.name);
        });
        // 清除动态路由
        router.removeRoute('home');
        // 清空数组
        store.menus = [];
        console.log(11);
    }
    i18n.locale.value = command
    store.changeLang(command)
    localStorage.setItem('lang', command)
};

const currentLanguage = computed(() => {
    return i18n.locale.value
})

const handlescreent = () => {
    if (screenfull.isEnabled) {
        screenfull.toggle()
        icon.value = !icon.value
    }
}

</script>

<style scoped lang="less">
.top-header {
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    section {
        display: flex;
        justify-content: space-between;
        align-items: center;

        .el-icon {
            color: #fff;
            font-size: 26px;
        }
    }

    h1 {
        font-size: 26px;
        margin: 0;
        margin-right: 40px;
    }
}
</style>
